package com.xuwang.service.impl;

import com.github.pagehelper.PageHelper;
import com.xuwang.Common.Constast;
import com.xuwang.Util.TableResult;
import com.xuwang.pojo.GovernmentPush;
import com.xuwang.mapper.GovernmentPushMapper;
import com.xuwang.pojo.GovernmentSupervisionPush;
import com.xuwang.pojo.User;
import com.xuwang.service.GovernmentPushService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (GovernmentPush)表服务实现类
 *
 * @author smallseven
 * @since 2021-09-14 19:24:42
 * @version 1.0
 */
@Service
public class GovernmentPushServiceImpl implements GovernmentPushService {
    @Resource
    private GovernmentPushMapper governmentPushMapper;


    /**
     * 将各类的咨询都返回
     * @return
     */
    @Override
    public TableResult<Map<Integer, List<GovernmentPush>>> push() {
        //首先先知道有哪些类型的咨询
        List<Integer> types=new ArrayList<>();
        types=governmentPushMapper.findTypes();
        //查询总条数
        int count= governmentPushMapper.findCount();

        //根据类型获取咨询
        PageHelper.startPage(1, 10);
        List<GovernmentPush> pushList;


        //组装不同类型的推送
        Map<Integer, List<GovernmentPush>> resultMap=new HashMap<>();

        for(Integer type:types){
            pushList=new ArrayList<>();
            pushList=governmentPushMapper.findPushByType(type);
            resultMap.put(type, pushList);
        }
        TableResult<Map<Integer, List<GovernmentPush>>> result=new TableResult<>(200,"推送文章返回成功",count,resultMap);
        return result;
    }


    /**
     * 政府监管推送
     * @return
     */
    @Override
    public TableResult<Map<Integer, List<GovernmentSupervisionPush>>> SupervisionPush() {
        //首先先知道有哪些类型的咨询
        List<Integer> types=new ArrayList<>();
        types=governmentPushMapper.findSupervisionTypes();
        //查询总条数
        int count= governmentPushMapper.findSupervisionCount();

        //根据类型获取咨询
        PageHelper.startPage(1, 10);
        List<GovernmentSupervisionPush> pushList;


        //组装不同类型的推送
        Map<Integer, List<GovernmentSupervisionPush>> resultMap=new HashMap<>();

        for(Integer type:types){
            pushList=new ArrayList<>();
            pushList=governmentPushMapper.findSupervisionPushByType(type);
            resultMap.put(type, pushList);
        }
        TableResult<Map<Integer, List<GovernmentSupervisionPush>>> result=new TableResult<>(200,"推送文章返回成功",count,resultMap);
        return result;
    }

    /**
     * 获取所有员工信息
     * @return
     */
    @Override
    public TableResult<List> getAllUser() {
        List<User> userList=new ArrayList<>();
       userList= governmentPushMapper.getAllUser();
        TableResult<List> result;
       if (userList != null && userList.size() > 0) {
           result  = new TableResult<>(200, Constast.SELECT_SUCCESS,userList.size(),userList);
       }else {
           result = new TableResult<>(500,Constast.ADMIN_NULL,0,null);
       }

        return result;
    }

    /**
     * 插入新的推送
     * @param governmentPush
     * @return
     */
    @Override
    public TableResult<String> insertPush(GovernmentPush governmentPush) {
        TableResult<String> result ;
        int isSucceed=governmentPushMapper.insertPush(governmentPush);
        if (isSucceed==1){
            result= new TableResult<>(200,"插入成功",1,"");
        }else {
            result = new TableResult<>(500,"插入失败",0,"");
        }
        return result;
    }


}
